** The Invisible Impact of Conflict: 
** Study of Terrorism, Regime Type, and Shadow Economy

* se-terror_final.dta is used 


xtset ccode year


/**1. panel tests 
*1. modified wald test
xtreg f.dge_p sum v2x_polyarchy remit fdipercent gdppc  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr, fe
xttest3

The null is homoskedasticity (or constant variance)
chi2 (132)  =     55769.00
Prob>chi2 =      0.0000  <-- presence of heteroskedasticity
*/
/**2. serial correlation test
xtserial dge_p sum v2x_polyarchy remit fdipercent gdppc  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr 
///The null is no serial correlation

Wooldridge test for autocorrelation in panel data
H0: no first-order autocorrelation
    F(  1,     113) =       362.350
           Prob > F =      0.0000  <--- presence of serial correlation
*/
/**3. cross sectional correlation test
xtreg dge_p sum, fe
xtcsd, pesaran abs

Pesaran's test of cross sectional independence =     301.370, Pr = 0.0000 <-- cross-sectional dependence
Average absolute value of the off-diagonal elements =      0.710
*/


**** Manuscript ****

** DV: dge_p
* Table 1 - Drisc/Kraay
xtscc f.dge_p c.sum v2x_polyarchy remit fdipercent gdppc  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr, fe lag(1)
outreg2 using table1.doc, ctitle(Model1) dec(3) replace 


xtscc f.dge_p c.sum##c.v2x_polyarchy remit fdipercent gdppc  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr, fe lag(1)
outreg2 using table1.doc, ctitle(Model2) dec(3) append 

xtscc f.dge_p c.sum v2x_polyarchy remit fdipercent gdppc  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr i.year, fe lag(1)
outreg2 using table1.doc, drop(i.year) ctitle(Model3) dec(3) append 

xtscc f.dge_p c.sum##c.v2x_polyarchy remit fdipercent gdppc  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr i.year, fe lag(1)
outreg2 using table1.doc, drop(i.year) dec(3) ctitle(Model4) append
 
sum dge_p c.sum c.v2x_polyarchy remit fdipercent gdppc  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr year if e(sample)

* list of countries
groups country if e(sample), show(none)



* Figure 1
margins, dydx(sum) at(v2x_polyarchy=(0 (0.2) 1))
marginsplot, yline(0, lcolor(black)) recast(line) recastci(rline) ///
ciopts(lpattern(dash) lcolor(gray)) legend(off) ///
	  addplot(histogram v2x_polyarchy if e(sample),   yaxis(2) yscale(alt axis(2)) lpattern(dash) lwidth(vthin) fcolor(none) lcolor(black)) 


* Table 2 - FGLS

xtgls f.dge_p c.sum c.v2x_polyarchy remit fdipercent gdppc  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr, corr(psar1) force
outreg2 using table2.doc, drop(i.year) dec(3) ctitle(Model1) replace
 
xtgls f.dge_p c.sum##c.v2x_polyarchy remit fdipercent gdppc  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr, corr(psar1) force
outreg2 using table2.doc, drop(i.year) dec(3) ctitle(Model2) append

xtgls f.dge_p c.sum c.v2x_polyarchy remit fdipercent gdppc  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr i.year, corr(psar1) force
outreg2 using table2.doc, drop(i.year) dec(3) ctitle(Model3) append

xtgls f.dge_p c.sum##c.v2x_polyarchy remit fdipercent gdppc  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr i.year, corr(psar1) force
outreg2 using table2.doc, drop(i.year) dec(3) ctitle(Model4) append	  



	  
* Figure 2
margins, dydx(sum) at(v2x_polyarchy=(0 (0.2) 1))
marginsplot, yline(0, lcolor(black)) recast(line) recastci(rline) ///
ciopts(lpattern(dash) lcolor(gray)) legend(off) ///
	  addplot(histogram v2x_polyarchy if e(sample),   yaxis(2) yscale(alt axis(2)) lpattern(dash) lwidth(vthin) fcolor(none) lcolor(black)) 


	  	
* Table A2 - Fixed
xtreg f.dge_p c.sum v2x_polyarchy remit fdipercent gdppc  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr, fe ro
outreg2 using tableA2.doc, ctitle(Model1) dec(3) replace 

xtreg f.dge_p c.sum##c.v2x_polyarchy remit fdipercent gdppc  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr, fe 
outreg2 using tableA2.doc, ctitle(Model2) dec(3) append 

xtreg f.dge_p c.sum v2x_polyarchy remit fdipercent gdppc  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr i.year, fe
outreg2 using tableA2.doc, drop(i.year) dec(3) ctitle(Model3) append 

xtreg f.dge_p c.sum##c.v2x_polyarchy remit fdipercent gdppc  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr i.year, fe
outreg2 using tableA2.doc, drop(i.year) dec(3) ctitle(Model4) append 


* Table A3 - GMM 
mata: mata set matafavor speed, perm

xtabond2 dge_p l.dge_p c.sum c.v2x_polyarchy remit fdipercent gdppc  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr i.year, gmm (l.(dge_p sum), lag(1 3)) ///
iv(v2x_polyarchy remit fdipercent gdppc  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr) ///
twostep  cluster(ccode)
outreg2 using tableA3.doc, drop(i.year) dec(3) ctitle(Model1) replace

xtabond2 dge_p l.dge_p c.sum##c.v2x_polyarchy remit fdipercent gdppc  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr i.year, gmm (l.(dge_p sum), lag(1 3)) ///
iv(v2x_polyarchy remit fdipercent gdppc  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr) ///
twostep  cluster(ccode)
outreg2 using tableA3.doc, drop(i.year) dec(3) ctitle(Model2) append 

mata: mata set matafavor space, perm

* Table A4 - Drisc/Kraay
xtscc f.dge_p c.sum income_n v2x_polyarchy remit fdipercent  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr i.year, fe lag(1)
outreg2 using tableA4.doc, drop(i.year) ctitle(Model1) dec(3) replace 

xtscc f.dge_p c.sum##c.income_n v2x_polyarchy remit fdipercent  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr i.year, fe lag(1)
outreg2 using tableA4.doc, drop(i.year) dec(3) ctitle(Model2) append
 


* Table A4 - v-dem and subsets
replace oda_gdp=0 if income=="High income" & oda_gdp==.

xtscc f.dge_p c.sum c.v2x_polyarchy remit fdipercent gdppc  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr v2csreprss v2cseeorgs v2x_clpriv v2xpe_exlecon v2xpe_exlgender v2xpe_exlpol v2xpe_exlsocgr v2x_jucon v2xlg_legcon i.year if sum>0, fe lag(1)
outreg2 using tableA4.doc, drop(i.year) dec(3) ctitle(Model1) replace


xtscc f.dge_p c.sum##c.v2x_polyarchy remit fdipercent gdppc  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr v2csreprss v2cseeorgs v2x_clpriv v2xpe_exlecon v2xpe_exlgender v2xpe_exlpol v2xpe_exlsocgr v2x_jucon v2xlg_legcon i.year if sum>0, fe lag(1)
outreg2 using tableA4.doc, drop(i.year) dec(3) ctitle(Model2) append


xtscc f.dge_p c.sum c.v2x_polyarchy remit fdipercent gdppc  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr i.year v2csreprss v2cseeorgs v2x_clpriv v2xpe_exlecon v2xpe_exlgender v2xpe_exlpol v2xpe_exlsocgr v2x_jucon v2xlg_legcon if country!="Pakistan" & country!="Nigeria" & country!="Yemen", fe lag(1)
outreg2 using tableA4.doc, drop(i.year) dec(3) ctitle(Model3) append

xtscc f.dge_p c.sum##c.v2x_polyarchy remit fdipercent gdppc  gdppcgrowth  trade urban logpop oda_gdp enrollment unemp v2x_corr i.year v2csreprss v2cseeorgs v2x_clpriv v2xpe_exlecon v2xpe_exlgender v2xpe_exlpol v2xpe_exlsocgr v2x_jucon v2xlg_legcon if country!="Pakistan" & country!="Nigeria" & country!="Yemen", fe lag(1)
outreg2 using tableA4.doc, drop(i.year) dec(3) ctitle(Model4) append


* corresponding author: 


